home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
games
/
mdlv13.zip
/
MDLSRC.ZIP
/
MDL_3D.CC
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-09
|
23KB
|
833 lines
//
// this file by brian martin 1996
// brian@phyast.pitt.edu
//
// this is part of the source for the MedDLe quake model viewer/editor
//
//
#include"mdl.h"
#include<grdriver.h>
// pre-calculated vertex normals needed to do shading
BG_3pt vertex_normal[162]={
{-0.525731,0.000000,0.850651},
{-0.442863,0.238856,0.864188},
{-0.295242,0.000000,0.955423},
{-0.309017,0.500000,0.809017},
{-0.162460,0.262866,0.951056},
{0.000000,0.000000,1.000000},
{0.000000,0.850651,0.525731},
{-0.147621,0.716567,0.681718},
{0.147621,0.716567,0.681718},
{0.000000,0.525731,0.850651},
{0.309017,0.500000,0.809017},
{0.525731,0.000000,0.850651},
{0.295242,0.000000,0.955423},
{0.442863,0.238856,0.864188},
{0.162460,0.262866,0.951056},
{-0.681718,0.147621,0.716567},
{-0.809017,0.309017,0.500000},
{-0.587785,0.425325,0.688191},
{-0.850651,0.525731,0.000000},
{-0.864188,0.442863,0.238856},
{-0.716567,0.681718,0.147621},
{-0.688191,0.587785,0.425325},
{-0.500000,0.809017,0.309017},
{-0.238856,0.864188,0.442863},
{-0.425325,0.688191,0.587785},
{-0.716567,0.681718,-0.147621},
{-0.500000,0.809017,-0.309017},
{-0.525731,0.850651,0.000000},
{0.000000,0.850651,-0.525731},
{-0.238856,0.864188,-0.442863},
{0.000000,0.955423,-0.295242},
{-0.262866,0.951056,-0.162460},
{0.000000,1.000000,0.000000},
{0.000000,0.955423,0.295242},
{-0.262866,0.951056,0.162460},
{0.238856,0.864188,0.442863},
{0.262866,0.951056,0.162460},
{0.500000,0.809017,0.309017},
{0.238856,0.864188,-0.442863},
{0.262866,0.951056,-0.162460},
{0.500000,0.809017,-0.309017},
{0.850651,0.525731,0.000000},
{0.716567,0.681718,0.147621},
{0.716567,0.681718,-0.147621},
{0.525731,0.850651,0.000000},
{0.425325,0.688191,0.587785},
{0.864188,0.442863,0.238856},
{0.688191,0.587785,0.425325},
{0.809017,0.309017,0.500000},
{0.681718,0.147621,0.716567},
{0.587785,0.425325,0.688191},
{0.955423,0.295242,0.000000},
{1.000000,0.000000,0.000000},
{0.951056,0.162460,0.262866},
{0.850651,-0.525731,0.000000},
{0.955423,-0.295242,0.000000},
{0.864188,-0.442863,0.238856},
{0.951056,-0.162460,0.262866},
{0.809017,-0.309017,0.500000},
{0.681718,-0.147621,0.716567},
{0.850651,0.000000,0.525731},
{0.864188,0.442863,-0.238856},
{0.809017,0.309017,-0.500000},
{0.951056,0.162460,-0.262866},
{0.525731,0.000000,-0.850651},
{0.681718,0.147621,-0.716567},
{0.681718,-0.147621,-0.716567},
{0.850651,0.000000,-0.525731},
{0.809017,-0.309017,-0.500000},
{0.864188,-0.442863,-0.238856},
{0.951056,-0.162460,-0.262866},
{0.147621,0.716567,-0.681718},
{0.309017,0.500000,-0.809017},
{0.425325,0.688191,-0.587785},
{0.442863,0.238856,-0.864188},
{0.587785,0.425325,-0.688191},
{0.688191,0.587785,-0.425325},
{-0.147621,0.716567,-0.681718},
{-0.309017,0.500000,-0.809017},
{0.000000,0.525731,-0.850651},
{-0.525731,0.000000,-0.850651},
{-0.442863,0.238856,-0.864188},
{-0.295242,0.000000,-0.955423},
{-0.162460,0.262866,-0.951056},
{0.000000,0.000000,-1.000000},
{0.295242,0.000000,-0.955423},
{0.162460,0.262866,-0.951056},
{-0.442863,-0.238856,-0.864188},
{-0.309017,-0.500000,-0.809017},
{-0.162460,-0.262866,-0.951056},
{0.000000,-0.850651,-0.525731},
{-0.147621,-0.716567,-0.681718},
{0.147621,-0.716567,-0.681718},
{0.000000,-0.525731,-0.850651},
{0.309017,-0.500000,-0.809017},
{0.442863,-0.238856,-0.864188},
{0.162460,-0.262866,-0.951056},
{0.238856,-0.864188,-0.442863},
{0.500000,-0.809017,-0.309017},
{0.425325,-0.688191,-0.587785},
{0.716567,-0.681718,-0.147621},
{0.688191,-0.587785,-0.425325},
{0.587785,-0.425325,-0.688191},
{0.000000,-0.955423,-0.295242},
{0.000000,-1.000000,0.000000},
{0.262866,-0.951056,-0.162460},
{0.000000,-0.850651,0.525731},
{0.000000,-0.955423,0.295242},
{0.238856,-0.864188,0.442863},
{0.262866,-0.951056,0.162460},
{0.500000,-0.809017,0.309017},
{0.716567,-0.681718,0.147621},
{0.525731,-0.850651,0.000000},
{-0.238856,-0.864188,-0.442863},
{-0.500000,-0.809017,-0.309017},
{-0.262866,-0.951056,-0.162460},
{-0.850651,-0.525731,0.000000},
{-0.716567,-0.681718,-0.147621},
{-0.716567,-0.681718,0.147621},
{-0.525731,-0.850651,0.000000},
{-0.500000,-0.809017,0.309017},
{-0.238856,-0.864188,0.442863},
{-0.262866,-0.951056,0.162460},
{-0.864188,-0.442863,0.238856},
{-0.809017,-0.309017,0.500000},
{-0.688191,-0.587785,0.425325},
{-0.681718,-0.147621,0.716567},
{-0.442863,-0.238856,0.864188},
{-0.587785,-0.425325,0.688191},
{-0.309017,-0.500000,0.809017},
{-0.147621,-0.716567,0.681718},
{-0.425325,-0.688191,0.587785},
{-0.162460,-0.262866,0.951056},
{0.442863,-0.238856,0.864188},
{0.162460,-0.262866,0.951056},
{0.309017,-0.500000,0.809017},
{0.147621,-0.716567,0.681718},
{0.000000,-0.525731,0.850651},
{0.425325,-0.688191,0.587785},
{0.587785,-0.425325,0.688191},
{0.688191,-0.587785,0.425325},
{-0.955423,0.295242,0.000000},
{-0.951056,0.162460,0.262866},
{-1.000000,0.000000,0.000000},
{-0.850651,0.000000,0.525731},
{-0.955423,-0.295242,0.000000},
{-0.951056,-0.162460,0.262866},
{-0.864188,0.442863,-0.238856},
{-0.951056,0.162460,-0.262866},
{-0.809017,0.309017,-0.500000},
{-0.864188,-0.442863,-0.238856},
{-0.951056,-0.162460,-0.262866},
{-0.809017,-0.309017,-0.500000},
{-0.681718,0.147621,-0.716567},
{-0.681718,-0.147621,-0.716567},
{-0.850651,0.000000,-0.525731},
{-0.688191,0.587785,-0.425325},
{-0.587785,0.425325,-0.688191},
{-0.425325,0.688191,-0.587785},
{-0.425325,-0.688191,-0.587785},
{-0.587785,-0.425325,-0.688191}
};
BG_Block *block;
void sort(float v[], int vi[], int left, int right);
void swap(float v[], int vi[], int i, int j);
int frame=0;
int firsttime=1;
int draw_flat=0,ii=5, draw_wire=0, draw_vertices=0;
int draw_gshade=0, draw_textured=0, draw_gtextured=1;
int show_head=0;
int back_color=0;
situation eyeball;
situation model;
void init_view(void);
BG_Polygon mdlpts;
GrContext *vscreen;
int mdl_3d(MDL_FILE *mddll)
{
char str[128];
byte mainloop=1;
byte cur_key=0;
FILE *in;
int i,j,k,l,jj,kk,ll,iii,jjj,kkk;
int zed=0;
int dumby,draw_poly;
int num_screen_pts=0;
int oldmx, oldmy;
int y_val;
int x_val;
int max_depth=128;
int update=1;
int num_screen_sides=0;
int cycle=0;
int p1,p2,p3,p4;
word usi;
word objects, blocks, sides, oblocks, osides, curblock,trackblocks;
word prev_y[BG_ScreenWidth];
unsigned ui,uj,uk,ul;
long unsigned map_max_x=1024;
long unsigned map_max_y=1024;
double forward=0,upward=0,rightward=0;
double t0,t1,frames, fps;
double dT=.03;
double view_angle;
double u,v,w;
double u0,v0,w0;
double a,b,c,d;
double aa,bb,cc,dd;
double front_plane=28.0, back_plane=10000.0, plane_const;
double z_scale_factor;
double zadd=5.0;
double scale_terra=.1;
struct time t;
float ftemp;
int maxn;
int draw_2d=0;
// to scale view
BG_Matrix scaling;
// the rotation matrices
BG_Matrix Rx,Ry,Rz;
BG_Matrix N,T,M,OTemp;
BG_Matrix M1,M2,M3;
BG_Matrix E_TM,B_TM,O_TM,Temp_TM,T_TM,TM;
BG_3pt *framemin, *framemax;
BG_3pt eye_ptlist[5000];
float xlist[5000];
int xindexlist[5000];
BG_3pt pt1, pt2, pt3, pt4, vect1, vect2, vect3;
BG_3pt light_ray;
BG_3pt LR; // light ray
BG_3pt MD; // move direction
BG_3pt vn[162];
BG_3pt X_axis,Y_axis, Z_axis; // move direction
BG_ScreenCoor pt[4];
BG_MouseRange(0,0,BG_ScreenWidth,BG_ScreenHeight);
BG_ClearScreen(0);
// create a screen buffer in ram to do rendering
vscreen = GrCreateContext(BG_ScreenWidth,BG_ScreenHeight,NULL,NULL);
G_buffer = (unsigned char *)(vscreen->gc_frame.gf_baseaddr[0]);
if(firsttime==1)init_view();
firsttime=0;
X_axis.x=10.0;
X_axis.y=0.0;
X_axis.z=0.0;
Y_axis.x=0.0;
Y_axis.y=10.0;
Y_axis.z=0.0;
Z_axis.x=0.0;
Z_axis.y=0.0;
Z_axis.z=10.0;
//Rotation Matrices
Rx=BG_CalcRx(0);
Ry=BG_CalcRy(0);
Rz=BG_CalcRz(0);
//Scaling matrix
BG_IdentityMatrix( &scaling );
//focus=20.0; // ~79 degree total view
scaling.m[0][0]=focus*(double)(BG_ScreenHeight-1)/win_height; //scale x
scaling.m[0][1]=(BG_ScreenWidth/2);
scaling.m[2][1]=(BG_ScreenHeight/2);
scaling.m[2][2]=-focus*(double)(BG_ScreenHeight-1)